/*
 *  constants.h
 *  joosVM
 *
 *  Created by Smári Waage on 1.7.2009.
 *  Copyright 2009 smari.org. All rights reserved.
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version.
 *  
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU General Public License for more details.
 *  
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 *  Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA. *
 */

#ifndef constants___ 
#define constants___ 

#include <stdlib.h>
#include <string>
#include "bytecode-list.h"


/*
 #
 #	Constants that can be changed.
 #
 */


//master switch for output
#define debugout 0  

// flags for debug output, nothing gets outputed unless the master switch is on.
#define debug_objects		0
#define debug_class_loader	0
#define debug_interpreter	0
#define debug_heap			0
#define debug_bytecodes		0
#define debug_stack			0
#define debug_gc			0
#define debug_gc_short		0
#define debug_trace			0
#define debug_trace_short	0


//If the Contracts are switched, then the result is pre and post conditions are checked during operations.
//This is mainly used for debugging purposes.
#define CONTRACTS 0


//Initial and Maximum heap Size
#define kHeapMaxSize 102400000 //100M
#define kHeapInitSize 100000  //100k 


/*
	Do not change anything below this line.
 #################################################################################
 */





#define CONSTANT_Utf8                   1
#define CONSTANT_Integer                3
#define CONSTANT_Float                  4
#define CONSTANT_Long                   5
#define CONSTANT_Double                 6
#define CONSTANT_Class                  7
#define CONSTANT_String                 8
#define CONSTANT_Fieldref               9
#define CONSTANT_Methodref              10
#define CONSTANT_InterfaceMethodref     11
#define CONSTANT_NameAndType            12

#define ACC_PUBLIC              0x0001
#define ACC_PRIVATE             0x0002
#define ACC_PROTECTED           0x0004
#define ACC_STATIC              0x0008
#define ACC_FINAL               0x0010
#define ACC_SYNCHRONIZED        0x0020
#define ACC_SUPER               0x0020
#define ACC_VOLATILE            0x0040
#define ACC_TRANSIENT           0x0080
#define ACC_NATIVE              0x0100
#define ACC_INTERFACE           0x0200
#define ACC_ABSTRACT            0x0400
#define ACC_SYNTHETIC           0x1000
#define ACC_ANNOTATION          0x2000
#define ACC_ENUM                0x4000
#define ACC_MIRANDA             0x0800

#define T_BOOLEAN               4
#define T_CHAR                  5       
#define T_FLOAT                 6
#define T_DOUBLE                7
#define T_BYTE                  8
#define T_SHORT                 9
#define T_INT                  10
#define T_LONG                 11






/* JoosVM Internal Types*/
#define IType_HeapObject	1
#define IType_Array			20
#define IType_StaticArray	21
#define IType_ByteArray		22
#define IType_String		23
#define IType_HashTable		24
#define IType_MethodArea	25
#define IType_TaggedArray	26
#define IType_TaggedValue	27
#define IType_HeapPrimitive 28
#define IType_HeapDblPrimitive 29
#define IType_JField		30
#define	IType_JStaticField	31
#define IType_JAbstractMethod  32
#define IType_JMethod		33
#define IType_JType			34
#define IType_Instance		35
#define IType_Frame			41
#define IType_Stack			42
#define IType_TraceTreeObject	51




//To be able to use comma in a macro, 
#define CFIX(c...) c

//For output
#if debugout
	#define dout(flag, args...) if(flag){printf("--# ");printf(args);}
#else
	#define dout(flag, args...)
#endif
//this is easier to find than just printf..
#define ddout(args...) printf(args);printf("\nFile:%s, \nLine:%i\n",__FILE__,__LINE__);


// a reminder assertion, to guard unimplemented stuff.
#define lassert(e,s) if(!e){printf("\nAssertion failed: %s, \nFile:%s, \nLine:%i\n",s,__FILE__,__LINE__);exit(1);}

#define JASSERT(x) if (!(x)){printf("\nAssertion failed: %s, \nFile:%s, \nLine:%i\n",#x,__FILE__,__LINE__);abort();}


//...My minor contracts.
#if CONTRACTS
	#define ASSERT(bool_expression) if (!(bool_expression)){printf("\nAssertion failed: %s, \nFile:%s, \nLine:%i\n",#bool_expression,__FILE__,__LINE__);abort();}
	#define REQUIRE(bool_expression) ASSERT(bool_expression)
	#define ENSURE(bool_expression) ASSERT(bool_expression)
	//#define INVARIANT(bool_expression)
#else
	#define ASSERT(ignore) 
	#define IS_VALID(ignore) 
	#define REQUIRE(ignore) 
	#define ENSURE(ignore) 
	//#define INVARIANT(bool_expression)
#endif


// a few types to make life easy, byte and not u1 because I use the word byte and it is not ambiguous like word which could be u2 or u4, dword.
typedef unsigned char byte; //u1
typedef unsigned short u2;	//word
typedef unsigned int u4;	//dword
typedef unsigned long long u8;	//qword
typedef union{
	uint64_t _long;
	double _double;
	struct{
		uint32_t high;
		uint32_t low;
	};
} u8_t;

typedef union{
	uint32_t _int;
	float _float;
} u4_t;

class Pointer;
class HeapObject;
class String;
class StaticArray;
class TaggedArray;
class Stack;
class MethodArea;
class JMethod;
class JType;



#endif
